package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@Slf4j
public class CategoryController {
 @Autowired
 private CategoryService categoryService;

 @PostMapping
 public R<String> save(@RequestBody Category category){
  log.info("新增分类");
  R<String> r = categoryService.get(category);
  return  r;
 }
 @GetMapping("/page")
 public R<Page> page(Integer page,Integer pageSize){
  Page pageInfo = categoryService.page(page, pageSize);
  return R.success(pageInfo);
 }
 @DeleteMapping()
 public R<String>delete(Long id){
  R<String> stringR = categoryService.delete(id);
  return stringR;
 }
 @PutMapping()
 public R<String>update(@RequestBody Category category){
  R<String> upDate = categoryService.upDate(category);
  return upDate;
 }
 @GetMapping("/list")
 public R<List<Category>> list(Category category){
  R<List<Category>> list = categoryService.list(category);
  return list;
 }
}


